package com.financing.wap.web.controller.api;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.financing.wap.common.ResultMap;
import com.financing.wap.dto.DstUserComplainDTO;
import com.financing.wap.service.IDstUserComplainService;
import com.financing.wap.util.StringUtil;
import com.financing.wap.web.controller.BaseController;
/***
 * 用户投诉
 *
 */
@Controller("dstUserComplainController")
@RequestMapping("/api/dstUserComplain")
public class DstUserComplainController extends BaseController  { 

	private Logger logger = Logger.getLogger(getClass());
	
	@Autowired
	private IDstUserComplainService dstUserComplainService;
	/***
	 * 用户投诉接口
	 * @param request
	 * @param dstUserComplain
	 * @return
	 */
	@RequestMapping("/addDstUserComplain")
	@ResponseBody
	public ResultMap add(HttpServletRequest request, DstUserComplainDTO dstUserComplain){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("add dstUserComplain  begin .......");
			
			
			String openid = request.getParameter("openid");
			if(StringUtil.isNullOrEmptyStr(openid)){
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}
			dstUserComplain.setUserOpenid(openid);
			
			int id = dstUserComplainService.insert(dstUserComplain);
			result.setAttribute("id", id);
			
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("add dstUserComplain list end .......");
		}catch(Exception e){
			log.error("add dstUserComplain error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		
		return result;
	}
	
	
}
